package com.ruoyi.web.controller.system;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.BAnjuan_af;
import com.ruoyi.system.domain.json.CorrespondingData;
import com.ruoyi.system.service.IBAnjuan_afService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 电子案卷新Controller
 *
 * @author guangpipi
 * @date 2023-09-21
 */
@RestController
@RequestMapping("/system/eanjuan")
public class BAnjuan_afController extends BaseController
{
    @Autowired
    private IBAnjuan_afService bEAnjuanService;

    /**
     * 查询电子案卷新列表
     */
//    //@PreAuthorize("@ss.hasPermi('system:anjuan:list')")
    @GetMapping("/list")
    public TableDataInfo list(BAnjuan_af bEAnjuan)
    {
        PageHelper.orderBy("anJuanName");
        List<BAnjuan_af> list = bEAnjuanService.selectBEAnjuanList(bEAnjuan);
        return getDataTable(list);
    }

    /**
     * 导出电子案卷新列表
     */
//    //@PreAuthorize("@ss.hasPermi('system:anjuan:export')")
    @Log(title = "电子案卷新", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BAnjuan_af bEAnjuan)
    {
        List<BAnjuan_af> list = bEAnjuanService.selectBEAnjuanList(bEAnjuan);
        ExcelUtil<BAnjuan_af> util = new ExcelUtil<BAnjuan_af>(BAnjuan_af.class);
        util.exportExcel(response, list, "电子案卷新数据");
    }


    @PostMapping("/integrityTesting")
    public CorrespondingData integrityTesting(@RequestBody BAnjuan_af bEAnjuan){
        String message = bEAnjuanService.integrityTesting(bEAnjuan);
        CorrespondingData correspondingData = new CorrespondingData();
        if(message.compareTo("文件完整，可通过！") == 0){
            correspondingData.setMsg("文件完整，可通过！");
        }else{
            List<String> res = bEAnjuanService.missingFiles(bEAnjuan);
            correspondingData.setMsg("文件有缺失，请及时补全！");
            correspondingData.setData(res);
        }
        return correspondingData;
    }


    /**
     * 获取电子案卷新详细信息
     */
//    //@PreAuthorize("@ss.hasPermi('system:anjuan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(bEAnjuanService.selectBEAnjuanById(id));
    }

    /**
     * 新增电子案卷新
     */
//    //@PreAuthorize("@ss.hasPermi('system:anjuan:add')")
    @Log(title = "电子案卷新", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BAnjuan_af bEAnjuan)
    {
        return toAjax(bEAnjuanService.insertBEAnjuan(bEAnjuan));
    }

    /**
     * 修改电子案卷新
     */
//    //@PreAuthorize("@ss.hasPermi('system:anjuan:edit')")
    @Log(title = "电子案卷新", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BAnjuan_af bEAnjuan)
    {
        return toAjax(bEAnjuanService.updateBEAnjuan(bEAnjuan));
    }

    /**
     * 删除电子案卷新
     */
//    //@PreAuthorize("@ss.hasPermi('system:anjuan:remove')")
    @Log(title = "电子案卷新", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(bEAnjuanService.deleteBEAnjuanByIds(ids));
    }
}
